#!/bin/bash

# $1=offset $2=no $3=count $4=total thread(1,2,4,8,16)
if [ $# != 4 ]
then
	echo "Usage: $0 offset machine-no count total-thread"	
	exit
fi

#offset and count: different instances of postmark use diff dir in /bwfs
offset=$1
no=$2
count=$3
total=$4
testdir=/home/test/postmark

pids[0]=0
time=0
while [ $time -lt 1]
do
#restart filesystem
	umount /bwfs && rmmod nfs && mount -t nfs 10.10.170.24:/nfs /bwfs
	echo 262144  >  /proc/fs/enfs/wthreshold
	echo 262144 >  /proc/fs/enfs/rthreshold
#execute start count process simultaneously
	rm -rf /tmp/pm-result*
	loop=0
	while [ $loop -lt $count ]
	do 
		dir=`expr $offset + $loop`
		
		rm -rf /bwfs/pmtest-$dir
		mkdir /bwfs/pmtest-$dir
			
		sed "/bwfs/c\set location \/bwfs\/pmtest-${dir}" $testdir/in > $testdir/in-bak
		$testdir/postmark < $testdir/in-bak > /tmp/pm-result-$total-$dir &
		pids=(${pids[@]}  $!) 

		loop=`expr $loop + 1`
	done

#collect data  
	for id in ${pids[@]}
	do	
		if [ $id != 0 ]
		then
			wait $pid
		fi	
	done
	copybak=/home/record/mulpro-inband
#It's strange that proc file can't be scped.
	cat /tmp/pm-result* > /tmp/pmtest
	scp /tmp/pmtest 10.10.170.21:/home/record/$copybak/$total/pmresult-$no-$time
	cp /proc/self/mountstats /tmp/
	scp /tmp/mountstats 10.10.170.21:/home/record/$copybak/$total/mountstats-$no-$time  
	time=`expr $time + 1`
done




